//
//  CarNewsTableViewCell.m
//  10-HomeWork
//
//  Created by dllo on 16/7/27.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "CarNewsTableViewCell.h"
#import "UIView+Frame.h"
#import "CarNews.h"
@interface CarNewsTableViewCell ()
@property (nonatomic, strong)UIImageView *carImageView;
@property (nonatomic, strong)UILabel *titlelabel;
@end

@implementation CarNewsTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        _carImageView = [[UIImageView alloc] initWithFrame:CGRectZero];
        _carImageView.backgroundColor = [UIColor redColor];
        [self.contentView addSubview:_carImageView];
        _titlelabel = [[UILabel alloc] initWithFrame:CGRectZero];
        _titlelabel.textAlignment = NSTextAlignmentCenter;
        _titlelabel.numberOfLines = 0;
        [self.contentView addSubview:_titlelabel];
    }
    return self;
}
- (void)layoutSubviews {
    [super layoutSubviews];
    CGFloat topMargin = 5;
    CGFloat bottomMargin = 5;
    CGFloat leftMargin = 5;
    CGFloat middleMargin = 5;
    
    _carImageView.frame = CGRectMake(leftMargin, topMargin, self.contentView.pf_width / 3, self.contentView.pf_height - topMargin - bottomMargin);
    _titlelabel.frame = CGRectMake(_carImageView.pf_width + leftMargin + middleMargin, topMargin, self.contentView.pf_width - _carImageView.pf_width - leftMargin - middleMargin, self.contentView.pf_height - topMargin - bottomMargin);
}
- (void)setCarNews:(CarNews *)carNews {
    _carNews = carNews;
    _carImageView.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:_carNews.imageName]]];
    _titlelabel.text = carNews.title;
}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
